<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>pgmpy.readwrite.BIF &#8212; pgmpy 0.1.2 documentation</title>
    
    <link rel="stylesheet" href="../../../_static/sphinxdoc.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../../',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true,
        SOURCELINK_SUFFIX: '.txt'
      };
    </script>
    <script type="text/javascript" src="../../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pgmpy 0.1.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" accesskey="U">Module code</a> &#187;</li> 
      </ul>
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/logo.png" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <form class="search" action="../../../search.html" method="get">
      <div><input type="text" name="q" /></div>
      <div><input type="submit" value="Go" /></div>
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <h1>Source code for pgmpy.readwrite.BIF</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">string</span> <span class="k">import</span> <span class="n">Template</span>

<span class="kn">import</span> <span class="nn">numpy</span>
<span class="kn">from</span> <span class="nn">pyparsing</span> <span class="k">import</span> <span class="n">Word</span><span class="p">,</span> <span class="n">alphanums</span><span class="p">,</span> <span class="n">Suppress</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">CharsNotIn</span><span class="p">,</span> <span class="n">Group</span><span class="p">,</span> <span class="n">nums</span><span class="p">,</span> <span class="n">ZeroOrMore</span><span class="p">,</span> <span class="n">OneOrMore</span><span class="p">,</span>\
    <span class="n">cppStyleComment</span><span class="p">,</span> <span class="n">printables</span>

<span class="kn">from</span> <span class="nn">pgmpy.models</span> <span class="k">import</span> <span class="n">BayesianModel</span>
<span class="kn">from</span> <span class="nn">pgmpy.factors.discrete</span> <span class="k">import</span> <span class="n">TabularCPD</span>
<span class="kn">from</span> <span class="nn">pgmpy.extern.six.moves</span> <span class="k">import</span> <span class="nb">map</span><span class="p">,</span> <span class="nb">range</span>


<div class="viewcode-block" id="BIFReader"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader">[docs]</a><span class="k">class</span> <span class="nc">BIFReader</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Base class for reading network file in bif format</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">string</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialisation of BifReader object</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------------</span>
<span class="sd">        path : file or str</span>
<span class="sd">                File of bif data</span>
<span class="sd">        string : str</span>
<span class="sd">                String of bif data</span>
<span class="sd">        Examples</span>
<span class="sd">        -----------------</span>
<span class="sd">        # dog-problem.bif file is present at</span>
<span class="sd">        # http://www.cs.cmu.edu/~javabayes/Examples/DogProblem/dog-problem.bif</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &lt;pgmpy.readwrite.BIF.BIFReader object at 0x7f2375621cf8&gt;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">path</span><span class="p">:</span>
            <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">network</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">network</span> <span class="o">=</span> <span class="n">network</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>

        <span class="k">elif</span> <span class="n">string</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">network</span> <span class="o">=</span> <span class="n">string</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Must specify either path or string&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="s1">&#39;&quot;&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">:</span>
            <span class="c1"># Replacing quotes by spaces to remove case sensitivity like:</span>
            <span class="c1"># &quot;Dog-Problem&quot; and Dog-problem</span>
            <span class="c1"># or &quot;true&quot;&quot;false&quot; and &quot;true&quot; &quot;false&quot; and true false</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">network</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s1">&#39;&quot;&#39;</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="p">)</span>

        <span class="k">if</span> <span class="s1">&#39;/*&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span> <span class="ow">or</span> <span class="s1">&#39;//&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">network</span> <span class="o">=</span> <span class="n">cppStyleComment</span><span class="o">.</span><span class="n">suppress</span><span class="p">()</span><span class="o">.</span><span class="n">transformString</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">)</span>  <span class="c1"># removing comments from the file</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">name_expr</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">state_expr</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">property_expr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variable_grammar</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">probability_expr</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">cpd_expr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_probability_grammar</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">network_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_network_name</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_names</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_variables</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_states</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_properties</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_property</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_parents</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_cpds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_values</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_edges</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_edges</span><span class="p">()</span>

<div class="viewcode-block" id="BIFReader.get_variable_grammar"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_variable_grammar">[docs]</a>    <span class="k">def</span> <span class="nf">get_variable_grammar</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">         A method that returns variable grammar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Defining a expression for valid word</span>
        <span class="n">word_expr</span> <span class="o">=</span> <span class="n">Word</span><span class="p">(</span><span class="n">alphanums</span> <span class="o">+</span> <span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span><span class="p">)</span>
        <span class="n">word_expr2</span> <span class="o">=</span> <span class="n">Word</span><span class="p">(</span><span class="n">initChars</span><span class="o">=</span><span class="n">printables</span><span class="p">,</span> <span class="n">excludeChars</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="p">])</span>
        <span class="n">name_expr</span> <span class="o">=</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;variable&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">word_expr</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;{&#39;</span><span class="p">)</span>
        <span class="n">state_expr</span> <span class="o">=</span> <span class="n">ZeroOrMore</span><span class="p">(</span><span class="n">word_expr2</span> <span class="o">+</span> <span class="n">Optional</span><span class="p">(</span><span class="n">Suppress</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">)))</span>
        <span class="c1"># Defining a variable state expression</span>
        <span class="n">variable_state_expr</span> <span class="o">=</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;type&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="n">word_expr</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;[&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="n">Word</span><span class="p">(</span><span class="n">nums</span><span class="p">))</span> <span class="o">+</span> \
            <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;]&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;{&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Group</span><span class="p">(</span><span class="n">state_expr</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;}&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;;&#39;</span><span class="p">)</span>
        <span class="c1"># variable states is of the form type description [args] { val1, val2 }; (comma may or may not be present)</span>

        <span class="n">property_expr</span> <span class="o">=</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;property&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">CharsNotIn</span><span class="p">(</span><span class="s1">&#39;;&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;;&#39;</span><span class="p">)</span>  <span class="c1"># Creating a expr to find property</span>

        <span class="k">return</span> <span class="n">name_expr</span><span class="p">,</span> <span class="n">variable_state_expr</span><span class="p">,</span> <span class="n">property_expr</span></div>

<div class="viewcode-block" id="BIFReader.get_probability_grammar"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_probability_grammar">[docs]</a>    <span class="k">def</span> <span class="nf">get_probability_grammar</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        A method that returns probability grammar</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Creating valid word expression for probability, it is of the format</span>
        <span class="c1"># wor1 | var2 , var3 or var1 var2 var3 or simply var</span>
        <span class="n">word_expr</span> <span class="o">=</span> <span class="n">Word</span><span class="p">(</span><span class="n">alphanums</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="s1">&#39;_&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="n">Optional</span><span class="p">(</span><span class="s2">&quot;|&quot;</span><span class="p">))</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="n">Optional</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">))</span>
        <span class="n">word_expr2</span> <span class="o">=</span> <span class="n">Word</span><span class="p">(</span><span class="n">initChars</span><span class="o">=</span><span class="n">printables</span><span class="p">,</span> <span class="n">excludeChars</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;,&#39;</span><span class="p">,</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="p">,</span> <span class="s1">&#39;(&#39;</span><span class="p">])</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="n">Optional</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">))</span>
        <span class="c1"># creating an expression for valid numbers, of the format</span>
        <span class="c1"># 1.00 or 1 or 1.00. 0.00 or 9.8e-5 etc</span>
        <span class="n">num_expr</span> <span class="o">=</span> <span class="n">Word</span><span class="p">(</span><span class="n">nums</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="s1">&#39;+&#39;</span> <span class="o">+</span> <span class="s1">&#39;e&#39;</span> <span class="o">+</span> <span class="s1">&#39;E&#39;</span> <span class="o">+</span> <span class="s1">&#39;.&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="n">Optional</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">))</span>
        <span class="n">probability_expr</span> <span class="o">=</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;probability&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;(&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">OneOrMore</span><span class="p">(</span><span class="n">word_expr</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;)&#39;</span><span class="p">)</span>
        <span class="n">optional_expr</span> <span class="o">=</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;(&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="n">OneOrMore</span><span class="p">(</span><span class="n">word_expr2</span><span class="p">))</span> <span class="o">+</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;)&#39;</span><span class="p">)</span>
        <span class="n">probab_attributes</span> <span class="o">=</span> <span class="n">optional_expr</span> <span class="o">|</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;table&#39;</span><span class="p">)</span>
        <span class="n">cpd_expr</span> <span class="o">=</span> <span class="n">probab_attributes</span> <span class="o">+</span> <span class="n">OneOrMore</span><span class="p">(</span><span class="n">num_expr</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">probability_expr</span><span class="p">,</span> <span class="n">cpd_expr</span></div>

    <span class="k">def</span> <span class="nf">variable_block</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">start</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">finditer</span><span class="p">(</span><span class="s1">&#39;variable&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">index</span> <span class="ow">in</span> <span class="n">start</span><span class="p">:</span>
            <span class="n">end</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">index</span><span class="o">.</span><span class="n">start</span><span class="p">())</span>
            <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">[</span><span class="n">index</span><span class="o">.</span><span class="n">start</span><span class="p">():</span><span class="n">end</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">probability_block</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">start</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">finditer</span><span class="p">(</span><span class="s1">&#39;probability&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">index</span> <span class="ow">in</span> <span class="n">start</span><span class="p">:</span>
            <span class="n">end</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">index</span><span class="o">.</span><span class="n">start</span><span class="p">())</span>
            <span class="k">yield</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">[</span><span class="n">index</span><span class="o">.</span><span class="n">start</span><span class="p">():</span><span class="n">end</span><span class="p">]</span>

<div class="viewcode-block" id="BIFReader.get_network_name"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_network_name">[docs]</a>    <span class="k">def</span> <span class="nf">get_network_name</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Retruns the name of the network</span>

<span class="sd">        Example</span>
<span class="sd">        ---------------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIF.BifReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.network_name()</span>
<span class="sd">        &#39;Dog-Problem&#39;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">start</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;network&#39;</span><span class="p">)</span>
        <span class="n">end</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">&#39;}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">start</span><span class="p">)</span>
        <span class="c1"># Creating a network attribute</span>
        <span class="n">network_attribute</span> <span class="o">=</span> <span class="n">Suppress</span><span class="p">(</span><span class="s1">&#39;network&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">Word</span><span class="p">(</span><span class="n">alphanums</span> <span class="o">+</span> <span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;{&#39;</span>
        <span class="n">network_name</span> <span class="o">=</span> <span class="n">network_attribute</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">network</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">end</span><span class="p">])[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">network_name</span></div>

<div class="viewcode-block" id="BIFReader.get_variables"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_variables">[docs]</a>    <span class="k">def</span> <span class="nf">get_variables</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns list of variables of the network</span>

<span class="sd">        Example</span>
<span class="sd">        -------------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.get_variables()</span>
<span class="sd">        [&#39;light-on&#39;,&#39;bowel_problem&#39;,&#39;dog-out&#39;,&#39;hear-bark&#39;,&#39;family-out&#39;]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variable_names</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">block</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_block</span><span class="p">():</span>
            <span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">variable_names</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">variable_names</span></div>

<div class="viewcode-block" id="BIFReader.get_states"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_states">[docs]</a>    <span class="k">def</span> <span class="nf">get_states</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the states of variables present in the network</span>

<span class="sd">        Example</span>
<span class="sd">        -----------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.get_states()</span>
<span class="sd">        {&#39;bowel-problem&#39;: [&#39;true&#39;,&#39;false&#39;],</span>
<span class="sd">        &#39;dog-out&#39;: [&#39;true&#39;,&#39;false&#39;],</span>
<span class="sd">        &#39;family-out&#39;: [&#39;true&#39;,&#39;false&#39;],</span>
<span class="sd">        &#39;hear-bark&#39;: [&#39;true&#39;,&#39;false&#39;],</span>
<span class="sd">        &#39;light-on&#39;: [&#39;true&#39;,&#39;false&#39;]}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variable_states</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">block</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_block</span><span class="p">():</span>
            <span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">variable_states</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">state_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span>

        <span class="k">return</span> <span class="n">variable_states</span></div>

<div class="viewcode-block" id="BIFReader.get_property"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_property">[docs]</a>    <span class="k">def</span> <span class="nf">get_property</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the property of the variable</span>

<span class="sd">        Example</span>
<span class="sd">        -------------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.get_property()</span>
<span class="sd">        {&#39;bowel-problem&#39;: [&#39;position = (335, 99)&#39;],</span>
<span class="sd">        &#39;dog-out&#39;: [&#39;position = (300, 195)&#39;],</span>
<span class="sd">        &#39;family-out&#39;: [&#39;position = (257, 99)&#39;],</span>
<span class="sd">        &#39;hear-bark&#39;: [&#39;position = (296, 268)&#39;],</span>
<span class="sd">        &#39;light-on&#39;: [&#39;position = (218, 195)&#39;]}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variable_properties</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">block</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_block</span><span class="p">():</span>
            <span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">name_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">properties</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">property_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="p">)</span>
            <span class="n">variable_properties</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">y</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">properties</span> <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">x</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">variable_properties</span></div>

<div class="viewcode-block" id="BIFReader.get_parents"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_parents">[docs]</a>    <span class="k">def</span> <span class="nf">get_parents</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the parents of the variables present in the network</span>

<span class="sd">        Example</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.get_parents()</span>
<span class="sd">        {&#39;bowel-problem&#39;: [],</span>
<span class="sd">        &#39;dog-out&#39;: [&#39;family-out&#39;, &#39;bowel-problem&#39;],</span>
<span class="sd">        &#39;family-out&#39;: [],</span>
<span class="sd">        &#39;hear-bark&#39;: [&#39;dog-out&#39;],</span>
<span class="sd">        &#39;light-on&#39;: [&#39;family-out&#39;]}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variable_parents</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">block</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">probability_block</span><span class="p">():</span>
            <span class="n">names</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">probability_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">variable_parents</span><span class="p">[</span><span class="n">names</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">=</span> <span class="n">names</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
        <span class="k">return</span> <span class="n">variable_parents</span></div>

<div class="viewcode-block" id="BIFReader.get_values"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_values">[docs]</a>    <span class="k">def</span> <span class="nf">get_values</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the CPD of the variables present in the network</span>

<span class="sd">        Example</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.get_values()</span>
<span class="sd">        {&#39;bowel-problem&#39;: np.array([[0.01],</span>
<span class="sd">                                    [0.99]]),</span>
<span class="sd">        &#39;dog-out&#39;: np.array([[0.99, 0.97, 0.9, 0.3],</span>
<span class="sd">                            [0.01, 0.03, 0.1, 0.7]]),</span>
<span class="sd">        &#39;family-out&#39;: np.array([[0.15],</span>
<span class="sd">                                [0.85]]),</span>
<span class="sd">        &#39;hear-bark&#39;: np.array([[0.7, 0.01],</span>
<span class="sd">                                [0.3, 0.99]]),</span>
<span class="sd">        &#39;light-on&#39;: np.array([[0.6, 0.05],</span>
<span class="sd">                            [0.4, 0.95]])}</span>
<span class="sd">         &quot;&quot;&quot;</span>
        <span class="n">variable_cpds</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">block</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">probability_block</span><span class="p">():</span>
            <span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">probability_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">cpds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">cpd_expr</span><span class="o">.</span><span class="n">searchString</span><span class="p">(</span><span class="n">block</span><span class="p">)</span>
            <span class="n">arr</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">j</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">cpds</span> <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="n">i</span><span class="p">]</span>
            <span class="k">if</span> <span class="s1">&#39;table&#39;</span> <span class="ow">in</span> <span class="n">block</span><span class="p">:</span>
                <span class="n">arr</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>
                <span class="n">arr</span> <span class="o">=</span> <span class="n">arr</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span><span class="p">[</span><span class="n">name</span><span class="p">]),</span>
                                   <span class="n">arr</span><span class="o">.</span><span class="n">size</span> <span class="o">//</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span><span class="p">[</span><span class="n">name</span><span class="p">])))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">length</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span><span class="p">[</span><span class="n">name</span><span class="p">])</span>
                <span class="n">reshape_arr</span> <span class="o">=</span> <span class="p">[[]</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">length</span><span class="p">)]</span>
                <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">arr</span><span class="p">):</span>
                    <span class="n">reshape_arr</span><span class="p">[</span><span class="n">i</span> <span class="o">%</span> <span class="n">length</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">val</span><span class="p">)</span>
                <span class="n">arr</span> <span class="o">=</span> <span class="n">reshape_arr</span>
                <span class="n">arr</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">arr</span><span class="p">)</span>
            <span class="n">variable_cpds</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">arr</span>

        <span class="k">return</span> <span class="n">variable_cpds</span></div>

<div class="viewcode-block" id="BIFReader.get_edges"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_edges">[docs]</a>    <span class="k">def</span> <span class="nf">get_edges</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the edges of the network</span>

<span class="sd">        Example</span>
<span class="sd">        --------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.get_edges()</span>
<span class="sd">        [[&#39;family-out&#39;, &#39;light-on&#39;],</span>
<span class="sd">         [&#39;family-out&#39;, &#39;dog-out&#39;],</span>
<span class="sd">         [&#39;bowel-problem&#39;, &#39;dog-out&#39;],</span>
<span class="sd">         [&#39;dog-out&#39;, &#39;hear-bark&#39;]]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">edges</span> <span class="o">=</span> <span class="p">[[</span><span class="n">value</span><span class="p">,</span> <span class="n">key</span><span class="p">]</span> <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
                 <span class="k">for</span> <span class="n">value</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span><span class="p">[</span><span class="n">key</span><span class="p">]]</span>
        <span class="k">return</span> <span class="n">edges</span></div>

<div class="viewcode-block" id="BIFReader.get_model"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFReader.get_model">[docs]</a>    <span class="k">def</span> <span class="nf">get_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the fitted bayesian model</span>

<span class="sd">        Example</span>
<span class="sd">        ----------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader</span>
<span class="sd">        &gt;&gt;&gt; reader = BIFReader(&quot;bif_test.bif&quot;)</span>
<span class="sd">        &gt;&gt;&gt; reader.get_model()</span>
<span class="sd">        &lt;pgmpy.models.BayesianModel.BayesianModel object at 0x7f20af154320&gt;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">model</span> <span class="o">=</span> <span class="n">BayesianModel</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_edges</span><span class="p">)</span>
            <span class="n">model</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">network_name</span>
            <span class="n">model</span><span class="o">.</span><span class="n">add_nodes_from</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_names</span><span class="p">)</span>

            <span class="n">tabular_cpds</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_cpds</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span>
                <span class="n">values</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_cpds</span><span class="p">[</span><span class="n">var</span><span class="p">]</span>
                <span class="n">cpd</span> <span class="o">=</span> <span class="n">TabularCPD</span><span class="p">(</span><span class="n">var</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span><span class="p">[</span><span class="n">var</span><span class="p">]),</span> <span class="n">values</span><span class="p">,</span>
                                 <span class="n">evidence</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span><span class="p">[</span><span class="n">var</span><span class="p">],</span>
                                 <span class="n">evidence_card</span><span class="o">=</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span><span class="p">[</span><span class="n">evidence_var</span><span class="p">])</span>
                                                <span class="k">for</span> <span class="n">evidence_var</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span><span class="p">[</span><span class="n">var</span><span class="p">]])</span>
                <span class="n">tabular_cpds</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cpd</span><span class="p">)</span>

            <span class="n">model</span><span class="o">.</span><span class="n">add_cpds</span><span class="p">(</span><span class="o">*</span><span class="n">tabular_cpds</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">node</span><span class="p">,</span> <span class="n">properties</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_properties</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">for</span> <span class="n">prop</span> <span class="ow">in</span> <span class="n">properties</span><span class="p">:</span>
                    <span class="n">prop_name</span><span class="p">,</span> <span class="n">prop_value</span> <span class="o">=</span> <span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">t</span><span class="p">:</span> <span class="n">t</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span> <span class="n">prop</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;=&#39;</span><span class="p">))</span>
                    <span class="n">model</span><span class="o">.</span><span class="n">node</span><span class="p">[</span><span class="n">node</span><span class="p">][</span><span class="n">prop_name</span><span class="p">]</span> <span class="o">=</span> <span class="n">prop_value</span>

            <span class="k">return</span> <span class="n">model</span>

        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s1">&#39;First get states of variables, edges, parents and network name&#39;</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="BIFWriter"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter">[docs]</a><span class="k">class</span> <span class="nc">BIFWriter</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Base class for writing BIF network file format</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">model</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialise a BIFWriter Object</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        model: BayesianModel Instance</span>

<span class="sd">        Examples</span>
<span class="sd">        ---------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFWriter</span>
<span class="sd">        &gt;&gt;&gt; writer = BIFWriter(model)</span>
<span class="sd">        &gt;&gt;&gt; writer</span>
<span class="sd">        &lt;writer_BIF.BIFWriter at 0x7f05e5ea27b8&gt;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">model</span><span class="p">,</span> <span class="n">BayesianModel</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s2">&quot;model must be an instance of BayesianModel&quot;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">model</span> <span class="o">=</span> <span class="n">model</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">name</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">network_name</span> <span class="o">=</span> <span class="s1">&#39;unknown&#39;</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">network_name</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_states</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">property_tag</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_properties</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_parents</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">tables</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>

<div class="viewcode-block" id="BIFWriter.BIF_templates"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter.BIF_templates">[docs]</a>    <span class="k">def</span> <span class="nf">BIF_templates</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Create template for writing in BIF format</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">network_template</span> <span class="o">=</span> <span class="n">Template</span><span class="p">(</span><span class="s1">&#39;network $name {</span><span class="se">\n</span><span class="s1">}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="c1"># property tag may or may not be present in model,and since no of properties</span>
        <span class="c1"># can be more than one , will replace them accoriding to format otherwise null</span>
        <span class="n">variable_template</span> <span class="o">=</span> <span class="n">Template</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;variable $name {</span>
<span class="s2">    type discrete [ $no_of_states ] { $states };</span>
<span class="s2">$properties}</span><span class="se">\n</span><span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>
        <span class="n">property_template</span> <span class="o">=</span> <span class="n">Template</span><span class="p">(</span><span class="s1">&#39;    property $prop ;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
        <span class="c1"># $variable_ here is name of variable, used underscore for clarity</span>
        <span class="n">probability_template</span> <span class="o">=</span> <span class="n">Template</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;probability ( $variable_$seprator_$parents ) {</span>
<span class="s2">    table $values ;</span>
<span class="s2">}</span><span class="se">\n</span><span class="s2">&quot;&quot;&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">network_template</span><span class="p">,</span> <span class="n">variable_template</span><span class="p">,</span> <span class="n">property_template</span><span class="p">,</span> <span class="n">probability_template</span></div>

    <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the BIF format as string</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">network_template</span><span class="p">,</span> <span class="n">variable_template</span><span class="p">,</span> <span class="n">property_template</span><span class="p">,</span> <span class="n">probability_template</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">BIF_templates</span><span class="p">()</span>
        <span class="n">network</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="n">network</span> <span class="o">+=</span> <span class="n">network_template</span><span class="o">.</span><span class="n">substitute</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">network_name</span><span class="p">)</span>
        <span class="n">variables</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>

        <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">variables</span><span class="p">):</span>
            <span class="n">no_of_states</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span><span class="p">[</span><span class="n">var</span><span class="p">]))</span>
            <span class="n">states</span> <span class="o">=</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_states</span><span class="p">[</span><span class="n">var</span><span class="p">])</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">property_tag</span><span class="p">[</span><span class="n">var</span><span class="p">]:</span>
                <span class="n">properties</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">properties</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
                <span class="k">for</span> <span class="n">prop_val</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">property_tag</span><span class="p">[</span><span class="n">var</span><span class="p">]:</span>
                    <span class="n">properties</span> <span class="o">+=</span> <span class="n">property_template</span><span class="o">.</span><span class="n">substitute</span><span class="p">(</span><span class="n">prop</span><span class="o">=</span><span class="n">prop_val</span><span class="p">)</span>
            <span class="n">network</span> <span class="o">+=</span> <span class="n">variable_template</span><span class="o">.</span><span class="n">substitute</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">var</span><span class="p">,</span> <span class="n">no_of_states</span><span class="o">=</span><span class="n">no_of_states</span><span class="p">,</span>
                                                    <span class="n">states</span><span class="o">=</span><span class="n">states</span><span class="p">,</span> <span class="n">properties</span><span class="o">=</span><span class="n">properties</span><span class="p">)</span>

        <span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">variables</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span><span class="p">[</span><span class="n">var</span><span class="p">]:</span>
                <span class="n">parents</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
                <span class="n">seprator</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">parents</span> <span class="o">=</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">variable_parents</span><span class="p">[</span><span class="n">var</span><span class="p">])</span>
                <span class="n">seprator</span> <span class="o">=</span> <span class="s1">&#39; | &#39;</span>
            <span class="n">cpd</span> <span class="o">=</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">tables</span><span class="p">[</span><span class="n">var</span><span class="p">]))</span>
            <span class="n">network</span> <span class="o">+=</span> <span class="n">probability_template</span><span class="o">.</span><span class="n">substitute</span><span class="p">(</span><span class="n">variable_</span><span class="o">=</span><span class="n">var</span><span class="p">,</span> <span class="n">seprator_</span><span class="o">=</span><span class="n">seprator</span><span class="p">,</span>
                                                       <span class="n">parents</span><span class="o">=</span><span class="n">parents</span><span class="p">,</span> <span class="n">values</span><span class="o">=</span><span class="n">cpd</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">network</span>

<div class="viewcode-block" id="BIFWriter.get_variables"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter.get_variables">[docs]</a>    <span class="k">def</span> <span class="nf">get_variables</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add variables to BIF</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        list: a list containing names of variable</span>

<span class="sd">        Example</span>
<span class="sd">        -------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader, BIFWriter</span>
<span class="sd">        &gt;&gt;&gt; model = BIFReader(&#39;dog-problem.bif&#39;).get_model()</span>
<span class="sd">        &gt;&gt;&gt; writer = BIFWriter(model)</span>
<span class="sd">        &gt;&gt;&gt; writer.get_variables()</span>
<span class="sd">        [&#39;bowel-problem&#39;, &#39;family-out&#39;, &#39;hear-bark&#39;, &#39;light-on&#39;, &#39;dog-out&#39;]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variables</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">variables</span></div>

<div class="viewcode-block" id="BIFWriter.get_states"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter.get_states">[docs]</a>    <span class="k">def</span> <span class="nf">get_states</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add states to variable of BIF</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        dict: dict of type {variable: a list of states}</span>

<span class="sd">        Example</span>
<span class="sd">        -------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader, BIFWriter</span>
<span class="sd">        &gt;&gt;&gt; model = BIFReader(&#39;dog-problem.bif&#39;).get_model()</span>
<span class="sd">        &gt;&gt;&gt; writer = BIFWriter(model)</span>
<span class="sd">        &gt;&gt;&gt; writer.get_states()</span>
<span class="sd">        {&#39;bowel-problem&#39;: [&#39;bowel-problem_0&#39;, &#39;bowel-problem_1&#39;],</span>
<span class="sd">         &#39;dog-out&#39;: [&#39;dog-out_0&#39;, &#39;dog-out_1&#39;],</span>
<span class="sd">         &#39;family-out&#39;: [&#39;family-out_0&#39;, &#39;family-out_1&#39;],</span>
<span class="sd">         &#39;hear-bark&#39;: [&#39;hear-bark_0&#39;, &#39;hear-bark_1&#39;],</span>
<span class="sd">         &#39;light-on&#39;: [&#39;light-on_0&#39;, &#39;light-on_1&#39;]}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variable_states</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="n">cpds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">cpd</span> <span class="ow">in</span> <span class="n">cpds</span><span class="p">:</span>
            <span class="n">variable</span> <span class="o">=</span> <span class="n">cpd</span><span class="o">.</span><span class="n">variable</span>
            <span class="n">variable_states</span><span class="p">[</span><span class="n">variable</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">state</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">cpd</span><span class="o">.</span><span class="n">get_cardinality</span><span class="p">([</span><span class="n">variable</span><span class="p">])[</span><span class="n">variable</span><span class="p">]):</span>
                <span class="n">variable_states</span><span class="p">[</span><span class="n">variable</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">variable</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;_&#39;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">state</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">variable_states</span></div>

<div class="viewcode-block" id="BIFWriter.get_properties"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter.get_properties">[docs]</a>    <span class="k">def</span> <span class="nf">get_properties</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add property to variables in BIF</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        dict: dict of type {variable: list of properties }</span>

<span class="sd">        Example</span>
<span class="sd">        -------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader, BIFWriter</span>
<span class="sd">        &gt;&gt;&gt; model = BIFReader(&#39;dog-problem.bif&#39;).get_model()</span>
<span class="sd">        &gt;&gt;&gt; writer = BIFWriter(model)</span>
<span class="sd">        &gt;&gt;&gt; writer.get_properties()</span>
<span class="sd">        {&#39;bowel-problem&#39;: [&#39;position = (335, 99)&#39;],</span>
<span class="sd">         &#39;dog-out&#39;: [&#39;position = (300, 195)&#39;],</span>
<span class="sd">         &#39;family-out&#39;: [&#39;position = (257, 99)&#39;],</span>
<span class="sd">         &#39;hear-bark&#39;: [&#39;position = (296, 268)&#39;],</span>
<span class="sd">         &#39;light-on&#39;: [&#39;position = (218, 195)&#39;]}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">variables</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">nodes</span><span class="p">()</span>
        <span class="n">property_tag</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">variable</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">variables</span><span class="p">):</span>
            <span class="n">properties</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">node</span><span class="p">[</span><span class="n">variable</span><span class="p">]</span>
            <span class="n">property_tag</span><span class="p">[</span><span class="n">variable</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">prop</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="n">properties</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="n">property_tag</span><span class="p">[</span><span class="n">variable</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">prop</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot; = &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">property_tag</span></div>

<div class="viewcode-block" id="BIFWriter.get_parents"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter.get_parents">[docs]</a>    <span class="k">def</span> <span class="nf">get_parents</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Add the parents to BIF</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        dict: dict of type {variable: a list of parents}</span>

<span class="sd">        Example</span>
<span class="sd">        -------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader, BIFWriter</span>
<span class="sd">        &gt;&gt;&gt; model = BIFReader(&#39;dog-problem.bif&#39;).get_model()</span>
<span class="sd">        &gt;&gt;&gt; writer = BIFWriter(model)</span>
<span class="sd">        &gt;&gt;&gt; writer.get_parents()</span>
<span class="sd">        {&#39;bowel-problem&#39;: [],</span>
<span class="sd">         &#39;dog-out&#39;: [&#39;bowel-problem&#39;, &#39;family-out&#39;],</span>
<span class="sd">         &#39;family-out&#39;: [],</span>
<span class="sd">         &#39;hear-bark&#39;: [&#39;dog-out&#39;],</span>
<span class="sd">         &#39;light-on&#39;: [&#39;family-out&#39;]}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cpds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
        <span class="n">cpds</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">variable</span><span class="p">)</span>
        <span class="n">variable_parents</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">cpd</span> <span class="ow">in</span> <span class="n">cpds</span><span class="p">:</span>
            <span class="n">variable_parents</span><span class="p">[</span><span class="n">cpd</span><span class="o">.</span><span class="n">variable</span><span class="p">]</span> <span class="o">=</span> <span class="p">[]</span>
            <span class="k">for</span> <span class="n">parent</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">cpd</span><span class="o">.</span><span class="n">variables</span><span class="p">[:</span><span class="mi">0</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">]):</span>
                <span class="n">variable_parents</span><span class="p">[</span><span class="n">cpd</span><span class="o">.</span><span class="n">variable</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">variable_parents</span></div>

<div class="viewcode-block" id="BIFWriter.get_cpds"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter.get_cpds">[docs]</a>    <span class="k">def</span> <span class="nf">get_cpds</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Adds tables to BIF</span>

<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        dict: dict of type {variable: array}</span>

<span class="sd">        Example</span>
<span class="sd">        -------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader, BIFWriter</span>
<span class="sd">        &gt;&gt;&gt; model = BIFReader(&#39;dog-problem.bif&#39;).get_model()</span>
<span class="sd">        &gt;&gt;&gt; writer = BIFWriter(model)</span>
<span class="sd">        &gt;&gt;&gt; writer.get_cpds()</span>
<span class="sd">        {&#39;bowel-problem&#39;: array([ 0.01,  0.99]),</span>
<span class="sd">         &#39;dog-out&#39;: array([ 0.99,  0.97,  0.9 ,  0.3 ,  0.01,  0.03,  0.1 ,  0.7 ]),</span>
<span class="sd">         &#39;family-out&#39;: array([ 0.15,  0.85]),</span>
<span class="sd">         &#39;hear-bark&#39;: array([ 0.7 ,  0.01,  0.3 ,  0.99]),</span>
<span class="sd">         &#39;light-on&#39;: array([ 0.6 ,  0.05,  0.4 ,  0.95])}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">cpds</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">model</span><span class="o">.</span><span class="n">get_cpds</span><span class="p">()</span>
        <span class="n">tables</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">cpd</span> <span class="ow">in</span> <span class="n">cpds</span><span class="p">:</span>
            <span class="n">tables</span><span class="p">[</span><span class="n">cpd</span><span class="o">.</span><span class="n">variable</span><span class="p">]</span> <span class="o">=</span> <span class="n">cpd</span><span class="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">tables</span></div>

<div class="viewcode-block" id="BIFWriter.write_bif"><a class="viewcode-back" href="../../../readwrite.html#pgmpy.readwrite.BIF.BIFWriter.write_bif">[docs]</a>    <span class="k">def</span> <span class="nf">write_bif</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Writes the BIF data into a file</span>

<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        filename : Name of the file</span>

<span class="sd">        Example</span>
<span class="sd">        -------</span>
<span class="sd">        &gt;&gt;&gt; from pgmpy.readwrite import BIFReader, BIFWriter</span>
<span class="sd">        &gt;&gt;&gt; model = BIFReader(&#39;dog-problem.bif&#39;).get_model()</span>
<span class="sd">        &gt;&gt;&gt; writer = BIFWriter(model)</span>
<span class="sd">        &gt;&gt;&gt; writer.write_bif(filname=&#39;test_file.bif&#39;)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">writer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__str__</span><span class="p">()</span>
        <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fout</span><span class="p">:</span>
            <span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">writer</span><span class="p">)</span></div></div>
</pre></div>

          </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pgmpy 0.1.2 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2016, Ankur Ankan.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.1.
    </div>
  </body>
</html>